var e = require("../../../../@babel/runtime/helpers/objectSpread2"), t = require("../../../../@babel/runtime/helpers/defineProperty"), i = getApp();

Component({
    properties: {},
    data: {
        popShow: !1,
        explainShow: !1,
        is_content: !1,
        is_notice: !1,
        invoice_type_index: 1,
        invoice_type_arr: [],
        invoice_header_index: 1,
        invoice_header_arr: [ {
            name: "个人",
            value: 1
        }, {
            name: "单位",
            value: 0
        } ],
        invoice_content_index: 1,
        invoice_content_arr: [],
        invoice_header_list: [],
        invoice_header_list_show: !1,
        invoice_explain: "",
        address: "",
        collect_name: "",
        gmf_taxpayer: "",
        gmf_bank: "",
        gmf_bank_admin: "",
        gmf_address: "",
        gmf_mobile: "",
        col_mobile: "",
        email: "",
        inputFocusName: ""
    },
    methods: {
        initData: function(e) {
            var t = e.address, i = e.sinvoice;
            if (1 == i.is_open && i.invoice_type.length >= 1) {
                var a = {
                    popShow: !0
                };
                a.invoice_type_arr = i.invoice_type, a.invoice_type_index = i.invoice_type[0].value, 
                a.invoice_content_arr = i.content, a.invoice_content_arr.push({
                    name: "不开发票",
                    value: 2
                }), a.invoice_content_index = a.invoice_content_arr[0].value, a.invoice_explain = i.notice, 
                a.invoice_header_list = i.rises;
                var n = i.default_rise, s = n.personal, o = n.special, _ = n.unit;
                a.personalRise = null != s ? s : {}, a.specialRise = null != o ? o : {}, a.unitRise = null != _ ? _ : {}, 
                this.data.address || (a.address = {
                    username: t.realname,
                    mobile: t.mobile,
                    col_address: t.address
                }), this.setData(a), this.setDefaultData(this.data.personalRise, 1);
            }
        },
        setDefaultData: function(e, t) {
            var i = e.col_address, a = e.col_mobile, n = e.col_name, s = e.collect_name, o = e.email, _ = e.gmf_address, l = e.gmf_bank, r = e.gmf_bank_admin, c = e.gmf_mobile, d = e.gmf_taxpayer, m = {};
            1 == t ? (m.collect_name = null != s ? s : "", m.col_mobile = null != a ? a : "", 
            m.email = null != o ? o : "", m.address = {}) : 2 != t && 3 != t || (m.collect_name = null != s ? s : "", 
            m.gmf_taxpayer = null != d ? d : "", m.gmf_bank = null != l ? l : "", m.gmf_bank_admin = null != r ? r : "", 
            m.gmf_address = null != _ ? _ : "", m.gmf_mobile = null != c ? c : "", m.col_mobile = null != a ? a : "", 
            m.email = null != o ? o : "", m.address = {
                realname: null != n ? n : "",
                mobile: null != a ? a : "",
                col_address: null != i ? i : ""
            }), this.setData(m);
        },
        send: function() {
            var e = this.data, t = e.invoice_type_index, a = e.invoice_header_index, n = e.invoice_content_index, s = e.collect_name, o = e.gmf_taxpayer, _ = e.gmf_bank, l = e.gmf_bank_admin, r = e.gmf_address, c = e.gmf_mobile, d = e.col_mobile, m = e.email, p = e.address;
            if ("2" == this.data.invoice_content_index && this.data.is_content) return this.closePop(), 
            !1;
            var u = {
                status: 2,
                apply: 1,
                invoice_type: t,
                rise_type: a,
                content: n
            };
            if (i._isTextEmpty(s)) return 0 == a || 2 == t ? i.tips("请输入单位名称") : i.tips("请输入发票抬头");
            if (u.collect_name = s, 2 == t || 0 == a) {
                if (i._isTextEmpty(o)) return i.tips("请输入纳税人识别号");
                if (2 == t) {
                    if (i._isTextEmpty(_)) return i.tips("请输入单位开户银行");
                    if (i._isTextEmpty(l)) return i.tips("请输入单位银行账号");
                    if (i._isTextEmpty(r)) return i.tips("请输入注册地址");
                    if (i._isTextEmpty(c)) return i.tips("请输入注册电话");
                }
                u.gmf_taxpayer = o, u.gmf_bank = _, u.gmf_bank_admin = l, u.gmf_address = r, u.gmf_mobile = c;
            }
            if (0 != t) {
                if (!p) return i.tips("请选择地址");
                u.col_address = p.col_address, u.col_name = p.username, u.col_mobile = p.mobile;
            }
            0 == t && (u.email = m, u.col_mobile = d), this.triggerEvent("confirm", u);
        },
        openAddList: function() {
            this.triggerEvent("openAddList");
        },
        setAddress: function(e) {
            var t, i, a = e;
            a.col_address = "".concat(e.province, " ").concat(e.city, " ").concat(e.district, " ").concat(null !== (t = e.street) && void 0 !== t ? t : "", " ").concat(null !== (i = e.address) && void 0 !== i ? i : ""), 
            this.setData({
                address: a
            });
        },
        setPopShow: function() {
            this.setData({
                popShow: !this.data.popShow
            });
        },
        closePop: function() {
            this.setData({
                invoice_type_index: 1,
                invoice_header_index: 1,
                invoice_content_index: 1,
                address: "",
                collect_name: "",
                gmf_taxpayer: "",
                gmf_bank: "",
                gmf_bank_admin: "",
                gmf_address: "",
                gmf_mobile: "",
                col_mobile: "",
                email: "",
                inputFocusName: ""
            }), this.setData({
                popShow: !1
            });
        },
        setExplainShow: function() {
            this.setData({
                explainShow: !this.data.explainShow
            });
        },
        setTabsIndex: function(e) {
            var i = e.currentTarget.dataset, a = i.value, n = i.name;
            this.setData(t({}, n, a));
            var s = this.data, o = s.invoice_header_index, _ = s.invoice_type_index, l = s.unitRise, r = s.specialRise, c = s.personalRise;
            "invoice_type_index" == n && 2 == _ ? this.setDefaultData(r, 3) : 0 == o ? this.setDefaultData(l, 2) : this.setDefaultData(c, 1);
        },
        setInvoiceHeaderListShow: function() {
            this.setData({
                invoice_header_list_show: !this.data.invoice_header_list_show
            });
        },
        setInvoiceHeader: function(t) {
            var i = t.currentTarget.dataset.content, a = i.collect_name, n = i.tax_num, s = i.bank, o = i.bank_admin, _ = i.address, l = i.mobile, r = {};
            1 == this.data.invoice_header_index ? r.collect_name = a : r = {
                collect_name: a,
                gmf_taxpayer: n,
                gmf_bank: s,
                gmf_bank_admin: o,
                gmf_address: _,
                gmf_mobile: l
            }, this.setData(e({
                invoice_header_list_show: !1
            }, r));
        },
        clearInputText: function(e) {
            var i = e.currentTarget.dataset.name;
            this.setData(t({}, i, ""));
        },
        inputFocus: function(e) {
            var t = e.currentTarget.dataset.name;
            this.setData({
                inputFocusName: t
            });
        },
        inputBlur: function() {
            var e, i = this.data.inputFocusName;
            this.setData((t(e = {}, i, this.data[i].replace(/\s+/g, "")), t(e, "inputFocusName", ""), 
            e));
        }
    }
});